<?php

class user extends Admin {

    private $status = array( 1 => '<b style="color:blue">已锁定</b>', 0 => '正常' );
    private $name = "用户";

    public function __construct() {
        parent::__construct();
        $this->group = $this->Cache()->get( 'userGroup' );
    }

    public function index( $c, $a ) {
        $this->table = $c;
        $result = $this->Paged()->findAll();
        $pager = $result[ 'page' ];
        $result = $result[ 'result' ];
        include $this->display( $c ); // 加载模板
    }


    public function edit( $c, $a ) {
        if ( !$id = intval( G( 'id' ) ) ) {
            exit( '非法修改用户!' );
        }
        $this->table = $c; // 数据库表名
        $result = $this->find( array( 'id' => $id ) ); // 查找数据
        include $this->display( $c ); // 加载模板
    }

    public function add( $c, $a ) {
        include $this->display( $c );
    }

    public function save( $c ) {
        # 获取表单数据
        foreach ( $_POST as $key => $val ) {

            $rows[ $key ] = htmlspecialchars( trim( $val ) );
             if('pass' == $key)
                 $rows[$key] = md6($rows[$key]);

        }

        # 注意 表单字段必须跟数据库表字段名一样
        $this->table = $c; // 数据库表名
        if ( $id = intval( G( "id" ) ) ) {
            $msg = $this->update( array( 'id' => $id ), $rows ) ? 'success' : 'failed';
        } else {
            $msg = $this->create( $rows ) ? 'success' : 'failed';
        }
        exit( $msg );
    }
}